import request from '@/utils/request'
import type { User, UserListParams, UserFormData, ResetPasswordParams, UpdateStatusParams } from '@/types/user'
import type { PageResult } from '@/types/common'

/**
 * 获取用户列表
 */
export function getUserList(params: UserListParams) {
  return request<PageResult<User>>({
    url: '/tenant/user/list',
    method: 'get',
    params,
  })
}

/**
 * 根据ID获取用户信息
 */
export function getUserById(id: number) {
  return request<User>({
    url: `/tenant/user/${id}`,
    method: 'get',
  })
}

/**
 * 创建用户
 */
export function createUser(data: UserFormData) {
  return request<User>({
    url: '/tenant/user',
    method: 'post',
    data,
  })
}

/**
 * 更新用户
 */
export function updateUser(id: number, data: Partial<UserFormData>) {
  return request<void>({
    url: `/tenant/user/${id}`,
    method: 'put',
    data,
  })
}

/**
 * 删除用户
 */
export function deleteUser(id: number) {
  return request<void>({
    url: `/tenant/user/${id}`,
    method: 'delete',
  })
}

/**
 * 修改用户状态
 */
export function updateUserStatus(id: number, data: UpdateStatusParams) {
  return request<void>({
    url: `/tenant/user/${id}/status`,
    method: 'put',
    data,
  })
}

/**
 * 重置用户密码
 */
export function resetPassword(id: number, data: ResetPasswordParams) {
  return request<void>({
    url: `/tenant/user/${id}/password`,
    method: 'put',
    data,
  })
}

/**
 * 获取所有开票员用户（用于订单筛选）
 */
export function getInvoicerUsers() {
  return request<User[]>({
    url: '/tenant/user/invoicers',
    method: 'get',
  })
}
